package com.qkjia.elasticsearchdemo;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @program: Byte2ShellCode
 * @description:
 * @author: luoguanhao 450372917@qq.com
 * @create: 2021-08-30 09:22
 **/
public class test {
    public static void main(String[] args) throws IOException {
        Path path = Paths.get("E:\\ShellCode.txt");
        byte data[]= Files.readAllBytes(path);
        String result = new String(data,"UTF-8");
        result=result.replaceAll(" ","");
       // result=result.replaceAll("\r\n","\"\r\n\"");
        byte[] data1 = result.getBytes();
        byte[] data2 =  new byte[data1.length*4];
        int j=0;
        int i=0;
        int temp=0;
        while(i<data1.length)
        {
            if(data1[i]=='\r')
            {
                temp=0;
            }
            if(data1[i]=='\n')
            {
                temp=0;
            }

           if((temp%4)==0)
           {
               data2[j]='\\';
               temp++;
               j++;
           }
            if((temp%4)==1)
            {
                data2[j] = 'x';
                temp++;
                j++;
            }
            else
            {
                temp++;
                data2[j]=data1[i];
                i++;
                j++;
            }


        }
        //System.out.println(data2);
        String str =new String(data2,"UTF-8");

        System.out.println(str);









   /*
        data3[data2.length + 4*LineNo] = '\"';

        String str = new String(data3,"UTF-8");
        System.out.println(str);
        FileOutputStream FileOutSteam = new FileOutputStream("F:\\ShellCodeOutPut.txt");
        FileOutSteam.write(data3);
        FileOutSteam.close();
        */

    }
}
